package com.whisperarts.financer.adapters;

import java.util.Map;

import com.whisperarts.financer.dao.AccountsDAO;
import com.whisperarts.financer.model.currency.Currency;

public class CurrencyAdapter {
	private final Map<String, Currency> currencies;
	private final String[] currencyCodes;
	private final String[] currencySymbols;

	public CurrencyAdapter() {
		currencies = AccountsDAO.getCurrencies();
		currencyCodes = new String[currencies.size()];
		currencySymbols = new String[currencies.size()];
		int i = 0;
		for (Currency currency : currencies.values()) {
			currencyCodes[i] = currency.getCode();
			currencySymbols[i] = currency.getSymbol();
			i++;
		}
	}
	
	public String[] getCurrencyCodes() {
		return currencyCodes;
	}

	public String[] getCurrencySymbols() {
		return currencySymbols;
	}
	
	public Currency getCurrencyByCode(String code) {
		return currencies.get(code);
	}

	public int getCurrencyIndex(Currency currency) {
		for (int i = 0; i < currencyCodes.length; i++) {
			if (currencyCodes[i].equals(currency.getCode()))
				return i;
		}
		return 0;
	}
}
